package com.jiangjiang.eshop.order.price.v1.factory;

import com.jiangjiang.eshop.common.constant.PromotionActivityType;
import com.jiangjiang.eshop.order.price.v1.calculator.FreightCalculator;
import com.jiangjiang.eshop.order.price.v1.calculator.PromotionActivityCalculator;
import com.jiangjiang.eshop.order.price.v1.calculator.TotalPriceCalculator;
import com.jiangjiang.eshop.order.price.v1.calculator.impl.*;
import com.jiangjiang.eshop.promotion.dto.PromotionActivityDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @Author Jianghaowen
 * @Date 2021/7/14
 * @Description: 赠品类型订单金额计算工厂
 * @Version V1.0
 **/
@Component
public class GiftOrderPriceCalculatorFactory implements OrderPriceCalculatorFactory {

    @Autowired
    private DefaultTotalPriceCalculator defaultTotalPriceCalculator;
    @Autowired
    private GiftIncludedFreightCalculator giftIncludedFreightCalculator;
    @Autowired
    private DefaultPromotionActivityCalculator defaultPromotionActivityCalculator;
    @Autowired
    private ReachGiftPromotionActivityCalculator reachGiftPromotionActivityCalculator;
    @Autowired
    private DirectGiftPromotionActivityCalculator directGiftPromotionActivityCalculator;

    @Override
    public TotalPriceCalculator createTotalPriceCalculator() {
        return defaultTotalPriceCalculator;
    }

    @Override
    public FreightCalculator createFreightCalculator() {
        return giftIncludedFreightCalculator;
    }

    @Override
    public PromotionActivityCalculator createPromotionActivityCalculator(PromotionActivityDTO promotionActivity) {
        if(Objects.isNull(promotionActivity)){
            return defaultPromotionActivityCalculator;
        }
        Integer type = promotionActivity.getType();
        if(PromotionActivityType.REACH_GIFT.equals(type)){
            return reachGiftPromotionActivityCalculator;
        } else if(PromotionActivityType.DIRECT_GIFT.equals(type)){
            return directGiftPromotionActivityCalculator;
        }else {
            return defaultPromotionActivityCalculator;
        }
    }
}
